<template>
  <div class="div">
    <a-modal
      title="选择服务"
      :width="modalWidth"
      :visible="visible"
      :confirmLoading="confirmLoading"
      @ok="handleCancel"
      @cancel="handleCancel"
    >
      <a-spin tip="Loading..." :spinning="false">
        <a-table :columns="columns" :data-source="data" :pagination="ipagination"  @change="handleTableChange">
          <span slot="action" slot-scope="text, record">
            <a @click="add(record)">选择</a>
          </span>
        </a-table>
      </a-spin>
    </a-modal>
  </div>
</template>

<script>
import { internetserviceList } from '@/api/api'
export default {
  name: 'JSelectCapabilityModal',
  props: ['modalWidth', 'multi', 'rootOpened', 'departId'],
  data() {
    return {
      visible: false,
      confirmLoading: false,
      data: [],
      ipagination:{
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      columns: [
       
        {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'服务id',
            align:"center",
            dataIndex: 'serviceId'
          },
          {
            title:'服务类型',
            align:"center",
            dataIndex: 'serviceType'
          },
          {
            title:'服务的描述',
            align:"center",
            dataIndex: 'description'
          },
          {
            title:'产品ID',
            align:"center",
            dataIndex: 'pid'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
    }
  },
  created() {
    this.loadDepart()
  },
  
  methods: {
    show() {
      this.visible = true

    },
    handleTableChange(pagination) {
    
      this.ipagination = pagination;
      this.loadDepart();
    },
    loadDepart() {
      internetserviceList({
        pageNo: this.ipagination.current ,
pageSize: 10
      }).then((res) => {
        
        if (res.success) {
          this.data = res.result.records
          this.ipagination.total = res.result.total;

          // let arr = [...res.result]
          // this.reWriterWithSlot(arr)
          // this.treeData = arr
          // this.initDepartComponent()
          // if (this.rootOpened) {
          //   this.initExpandedKeys(res.result)
          // }
        }
      })
    },
     handleCancel() {
      this.visible = false
    },
    // 选择服务id
    add(val){
      console.log(val.serviceId)
       this.$emit('ok', val.serviceId)
      this.visible = false
    }
  },
}
</script>

<style scoped>
.ant-modal-wrap >>> .ant-modal {
  width: 1200px !important;
}
</style>